<!DOCTYPE html>
<html lang="en-us">
<head>
	<meta charSet="UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1" />
	<link rel="apple-touch-icon" sizes="57x57" href="/CsvHelper/favicons/apple-icon-57x57.png" />
	<link rel="apple-touch-icon" sizes="60x60" href="/CsvHelper/favicons/apple-icon-60x60.png" />
	<link rel="apple-touch-icon" sizes="72x72" href="/CsvHelper/favicons/apple-icon-72x72.png" />
	<link rel="apple-touch-icon" sizes="76x76" href="/CsvHelper/favicons/apple-icon-76x76.png" />
	<link rel="apple-touch-icon" sizes="114x114" href="/CsvHelper/favicons/apple-icon-114x114.png" />
	<link rel="apple-touch-icon" sizes="120x120" href="/CsvHelper/favicons/apple-icon-120x120.png" />
	<link rel="apple-touch-icon" sizes="144x144" href="/CsvHelper/favicons/apple-icon-144x144.png" />
	<link rel="apple-touch-icon" sizes="152x152" href="/CsvHelper/favicons/apple-icon-152x152.png" />
	<link rel="apple-touch-icon" sizes="180x180" href="/CsvHelper/favicons/apple-icon-180x180.png" />
	<link rel="icon" type="image/png" sizes="192x192" href="/CsvHelper/favicons/android-icon-192x192.png" />
	<link rel="icon" type="image/png" sizes="32x32" href="/CsvHelper/favicons/favicon-32x32.png" />
	<link rel="icon" type="image/png" sizes="96x96" href="/CsvHelper/favicons/favicon-96x96.png" />
	<link rel="icon" type="image/png" sizes="16x16" href="/CsvHelper/favicons/favicon-16x16.png" />
	<link rel="manifest" href="/CsvHelper/manifest.json" />
	<meta name="msapplication-TileColor" content="#ffffff" />
	<meta name="msapplication-TileImage" content="/ms-icon-144x144.png" />
	<meta name="theme-color" content="#ffffff" />
	<title>Auto Mapping | CsvHelper</title>

	
	
		<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.9.1/css/bulma.min.css" />
	
	<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/default.min.css" />
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/vs.min.css" />
	<link rel="stylesheet" href="/CsvHelper/styles/index.css" />

	<script defer src="https://use.fontawesome.com/releases/v5.14.0/js/all.js"></script>
	<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.min.js"></script>
</head>
<body>
	<header id="header" class="header">
	<nav class="navbar is-light">
		<div class="navbar-brand">
			<a class="navbar-item" href="/CsvHelper">
				<img src="/CsvHelper/images/logo.svg" width="66" height="28" />
			</a>
			<div id="navbar-burger" class="navbar-burger">
				<span></span>
				<span></span>
				<span></span>
			</div>
		</div>
		<div id="navbar-menu" class="navbar-menu">
			<div class="navbar-start">
				<a class="navbar-item" href="/CsvHelper/getting-started">Getting Started</a>
				<a class="navbar-item" href="/CsvHelper/examples">Examples</a>
				<a class="navbar-item" href="/CsvHelper/migration">Migration</a>
				<a class="navbar-item" href="/CsvHelper/change-log">Change Log</a>
			</div>
			<div class="navbar-end">
				<a class="navbar-item" href="https://twitter.com/JoshClose">
					<span class="icon">
						<i class="fab fa-twitter"></i>
					</span>
				</a>
				<a class="navbar-item" href="https://github.com/JoshClose/CsvHelper">
					<span class="icon">
						<i class="fab fa-github"></i>
					</span>
				</a>
			</div>
		</div>
	</nav>
</header>


	<main id="main" class="container is-fluid">
		<div class="columns is-variable is-1">
					<div class="column is-2">
						
<div id="sidebar" class="sidebar">
	<ul class="">
		<li>
	<span>
			<a class="expander"></a>

		<a href="/CsvHelper/examples/prerequisites">Prerequisites</a>
	</span>

		<ul class="is-hidden">
		<li>
	<span>

		<a href="/CsvHelper/examples/prerequisites/using-and-dispose">Using and Dispose</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/prerequisites/reading-and-writing-files">Reading and Writing Files</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/prerequisites/streams">Streams</a>
	</span>

</li>

</ul>

</li>

		<li>
	<span>
			<a class="expander"></a>

		<a href="/CsvHelper/examples/reading">Reading</a>
	</span>

		<ul class="is-hidden">
		<li>
	<span>

		<a href="/CsvHelper/examples/reading/get-class-records">Get Class Records</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/reading/get-dynamic-records">Get Dynamic Records</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/reading/get-anonymous-type-records">Get Anonymous Type Records</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/reading/enumerate-class-records">Enumerate Class Records</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/reading/reading-by-hand">Reading by Hand</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/reading/reading-multiple-data-sets">Reading Multiple Data Sets</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/reading/reading-multiple-record-types">Reading Multiple Record Types</a>
	</span>

</li>

</ul>

</li>

		<li>
	<span>
			<a class="expander"></a>

		<a href="/CsvHelper/examples/writing">Writing</a>
	</span>

		<ul class="is-hidden">
		<li>
	<span>

		<a href="/CsvHelper/examples/writing/write-class-objects">Write Class Objects</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/writing/write-dynamic-objects">Write Dynamic Objects</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/writing/write-anonymous-type-objects">Write Anonymous Type Objects</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/writing/appending-to-an-existing-file">Appending to an Existing File</a>
	</span>

</li>

</ul>

</li>

		<li>
	<span>
			<a class="expander"></a>

		<a href="/CsvHelper/examples/configuration">Configuration</a>
	</span>

		<ul class="is-hidden">
		<li>
	<span>
			<a class="expander"></a>

		<a href="/CsvHelper/examples/configuration/class-maps">Class Maps</a>
	</span>

		<ul class="is-hidden">
		<li>
	<span>

		<a href="/CsvHelper/examples/configuration/class-maps/mapping-properties">Mapping Properties</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/configuration/class-maps/mapping-by-name">Mapping by Name</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/configuration/class-maps/mapping-by-alternate-names">Mapping by Alternate Names</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/configuration/class-maps/mapping-duplicate-names">Mapping Duplicate Names</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/configuration/class-maps/mapping-by-index">Mapping by Index</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/configuration/class-maps/auto-mapping">Auto Mapping</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/configuration/class-maps/ignoring-properties">Ignoring Properties</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/configuration/class-maps/constant-value">Constant Value</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/configuration/class-maps/type-conversion">Type Conversion</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/configuration/class-maps/inline-type-conversion">Inline Type Conversion</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/configuration/class-maps/optional-maps">Optional Maps</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/configuration/class-maps/validation">Validation</a>
	</span>

</li>

</ul>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/configuration/attributes">Attributes</a>
	</span>

</li>

</ul>

</li>

		<li>
	<span>
			<a class="expander"></a>

		<a href="/CsvHelper/examples/type-conversion">Type Conversion</a>
	</span>

		<ul class="is-hidden">
		<li>
	<span>

		<a href="/CsvHelper/examples/type-conversion/type-converter-options">Type Converter Options</a>
	</span>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/type-conversion/custom-type-converter">Custom Type Converters</a>
	</span>

</li>

</ul>

</li>

		<li>
	<span>

		<a href="/CsvHelper/examples/csvdatareader">CsvDataReader</a>
	</span>

</li>

		<li>
	<span>

		<a href="#">Back to top</a>
	</span>

</li>

</ul>

</div>

					</div>
				<div class="column">
					<div class="content">
						<h1 id="auto-mapping">Auto Mapping</h1>
<p>If you don't supply a map to the configuration, one is automatically created for you on the fly. You can call auto mapping directly in your class map also. You may want to do this if you have a large number of properties that will be set up correctly by default, and only need to make a couple changes.</p>
<h6 id="data">Data</h6>
<pre><code>Id,The Name
1,one
</code></pre>
<h6 id="example">Example</h6>
<pre><code class="language-cs">void Main()
{	   
	using (var reader = new StreamReader(&quot;path\\to\\file.csv&quot;))
    using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
    {
        csv.Context.RegisterClassMap&lt;FooMap&gt;();
        var records = csv.GetRecords&lt;Foo&gt;();
    }
}

public class Foo
{
	public int Id { get; set; }
	public string Name { get; set; }
}

public sealed class FooMap : ClassMap&lt;Foo&gt;
{
	public FooMap()
	{
		AutoMap(CultureInfo.InvariantCulture);
		Map(m =&gt; m.Name).Name(&quot;The Name&quot;);
	}
}
</code></pre>

					</div>
				</div>
		</div>
	</main>

	<br /><br />

	<footer id="footer" class="footer">
	<div class="has-text-centered">&copy; 2009-2024 Josh Close</div>
</footer>



	<script>
		hljs.configure({
			tabReplace: "    "
		});
		hljs.initHighlightingOnLoad();
	</script>
	<script src="/CsvHelper/scripts/header.js"></script>
	<script src="/CsvHelper/scripts/sidebar.js"></script>
	
</body>
</html>
